#include <org_zxstudio_encrypt_task_FileEncryptMachine.h>
#include <stdio.h>
#include "simple_encrypt.h"
#include <stdlib.h>
#include <string.h>
#include <android/log.h>
#define  ENCRYPT_PATH   "/mnt/sdcard/.an/"
#define LOG_TAG "NativeEncrypt"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

JNIEXPORT jboolean JNICALL Java_org_zxstudio_encrypt_task_FileEncryptMachine_encrypt
  (JNIEnv * env, jclass obj, jstring source, jstring dest) {
	const char *oFileName = (*env)->GetStringUTFChars(env, source, NULL);
	if (oFileName == NULL) {
		return JNI_FALSE;
	}

	const char *nFileName = (*env)->GetStringUTFChars(env, dest, NULL);
	if (nFileName == NULL) {
		return JNI_FALSE;
	}

	//const char *password = (*env)->GetStringUTFChars(env, pwd, NULL);

	/*if (strlen(password) == 0) {

		if (keys[0] == NULL) {
			*
			 * 生成密钥并加密


		}

	} else {
		encrypt(oFileName, nFileName, password);
	}*/
	encryptKeys();
	encrypt(oFileName, nFileName, keys);
	return JNI_TRUE;
}

JNIEXPORT jboolean JNICALL Java_org_zxstudio_encrypt_task_FileEncryptMachine_decrypt
  (JNIEnv * env, jclass obj, jstring source, jstring dest) {
	const char *oFileName = (*env)->GetStringUTFChars(env, source, NULL);
		if (oFileName == NULL) {
			return JNI_FALSE;
		}

		const char *nFileName = (*env)->GetStringUTFChars(env, dest, NULL);
		if (nFileName == NULL) {
			return JNI_FALSE;
		}

		//const char *password = (*env)->GetStringUTFChars(env, pwd, NULL);

	/*	if (strlen(password) == 0) {

			if (keys[0] == NULL) {
				*
				 * 生成密钥并加密

				encryptKeys();
			}

			encrypt(oFileName, nFileName, keys);
		} else {
			encrypt(oFileName, nFileName, password);
		}*/
		encryptKeys();
		encrypt(oFileName, nFileName, keys);
		return JNI_TRUE;
}
